|
|
|
|
|
|
|
(table continued from previous page) |
|
|
|
|
| Property | Value | Description | | ListField | St_Desc | The field to be displayed in the list | | RowSource | StatesDB | The Data control containing the data used to populate the list |
|
|
|
|
|
|
For this example, set the properties of the data-bound combo box as listed in Table 10.5. Try running the application and displaying the data-entry form to see how the combo box works. Then add the code to allow users to add a new state abbreviation and its description to the reference table. After the new entry is added, the data control for the combo box is refreshed and positioned to the new entry. The code in Listing 10.13 performs these actions by using the ActiveX Data control methods and ADO commands. |
|
|
|
|
|
|
|
|
LISTING 10.13. ADDRADO6.TXTADDING THE CODE TO ADD NEW STATES TO THE REFERENCE TABLE AS NEEDED. |
|
|
|
 |
|
|
|
|
1: Private Sub dbcboState_LostFocus()
2: Dim hold_State As String
3: If dbcboState.Text = Or IsNull(dbcboState.Text) Or _
dbcboState.Text = _
4: Then Exit Sub
5: hold_State = dbcboState.BoundText
6: MyDyn.Open(SELECT * FROM States, MyDb,,,adCmdText
7: MyDyn.Find St_Abbrev = & hold_State & , adSearchForward
8: If MyDyn.NoMatch Then
9: MyDyn.AddNew
10: MyDyn.Fields(St_Abbrev).Value = hold_State
11: MyDyn.Fields(St_Desc).Value = InputBox(Enter the _
Description for: _
12: & hold_State, App.Title, N/A)
13: hold_State = MyDyn.Fields(St_Desc).Value
14: MyDyn.Update
15: MyDyn.Close
16: StatesDB.Requery
17: dbcboState.Text = hold_State
18: End If
19: End Sub |
|
|
|
|
|
|
|
|
In this code, you can see that although the ActiveX Data control is used to populate the combo box, ActiveX Data Objects are used to check whether the state entered by users exists and, if not, to add it to the reference table. It also prompts users for the state's full name. This whole process works because you're controlling the position of the current record pointer and the contents of the text property. Try running the application again and add a new state to an entry. You'll see it added to the drop-down list and placed in the text area so that the abbreviation is added to the address entry record. |
|
|
|
|
|